package com.flymobi.mshop.activity;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.flymobi.mshop.R;
import com.flymobi.mshop.util.MyApplication;

//Ӧ�ó����ܳ������,��Ӧ������activity�̳и���
public abstract class CommonActivity extends Activity {
	protected static Map<String, Object> params = new HashMap<String, Object>();
	protected static CommonActivity context;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		context = this;
	}

	// ����ͨ�õķ������̳е����඼����
	// �ڱ�activity�д�һ����activity
	public <T> void forward(Class<T> activity) {
		Intent direct = new Intent(this, activity);
		direct.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(direct);
		overridePendingTransition(R.anim.right_in, R.anim.left_out);
	}
	
	public <T> void forwardRight(Class<T> activity) {
		Intent direct = new Intent(this, activity);
		direct.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(direct);
		overridePendingTransition(R.anim.right_in, R.anim.left_out);
	}
	
	public <T> void forwardUp(Class<T> activity) {
		Intent direct = new Intent(this, activity);
		direct.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(direct);
		overridePendingTransition(R.anim.up_in, R.anim.down_out);
	}
	
	public <T> void forwardDown(Class<T> activity) {
		Intent direct = new Intent(this, activity);
		direct.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(direct);
		overridePendingTransition(R.anim.down_in, R.anim.up_out);
	}

	public <T> void forwardFade(Class<T> activity) {
		Intent direct = new Intent(this, activity);
		direct.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(direct);
		overridePendingTransition(R.anim.fade_in, R.anim.fade_out);// �л�Activity�Ĺ�ɶ�
	}

	public <T> void forwardZoom(Class<T> activity) {
		Intent direct = new Intent(this, activity);
		direct.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(direct);
		overridePendingTransition(R.anim.zoomin, R.anim.zoomhold);
	}

	public <T> void forwardResult(Class<T> activity) {
		Intent direct = new Intent(this, activity);
		direct.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		this.startActivityForResult(direct, 1);
	}

	public View getView(int layout) {
		LayoutInflater inflater = (LayoutInflater) LayoutInflater.from(this);
		View view = (View) inflater.inflate(layout, null);
		return view;
	}


	public Object set(String key, Object value) {
		return params.put(key, value);
	}

	public Object get(String key) {
		return params.get(key);
	}

	public Object remove(String key) {
		return params.remove(key);
	}

	public Toast showMsg(CharSequence msg) {
		Toast t = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
		t.setGravity(Gravity.CENTER, 0, 0);
		t.show();
		return t;
	}

	public Toast showLongMsg(String msg) {
		Toast t = Toast.makeText(this, msg, Toast.LENGTH_LONG);
		t.setGravity(Gravity.CENTER, 0, 0);
		t.show();
		return t;
	}
}